package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.dto.QueryDeviceDataDto;
import com.zzyl.nursing.domain.DeviceData;
import com.zzyl.nursing.domain.FamilyMember;
import com.zzyl.nursing.dto.DeviceDto;
import com.zzyl.nursing.dto.MemberAddDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.service.IDeviceDataService;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.vo.DeviceVo;
import com.zzyl.nursing.vo.LoginVo;
import com.zzyl.nursing.vo.QueryDeviceDataVo;
import com.zzyl.nursing.vo.MamberElderVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 老人家属Controller
 * 
 * @author alexis
 * @date 2025-01-09
 */
@Api(tags = "老人家属管理")
@RestController
@RequestMapping("/member/user")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;

    @Autowired
    private IDeviceDataService deviceDataService;

    @PostMapping("/login")
    public R<LoginVo> login(@RequestBody UserLoginRequestDto userLoginRequestDto) {
        // 调用Service层接口进行小程序登录
        LoginVo loginVo = familyMemberService.login(userLoginRequestDto);
        return R.ok(loginVo);
    }
    //绑定家属
    @PostMapping("/add")
    public R<FamilyMember> add(@RequestHeader("authorization") String authorization, @RequestBody MemberAddDto memberAddDto){
       return familyMemberService.addRemark(memberAddDto, authorization);
    }

    /**
     * 分页查看已绑定家人列表
     * @param authorization
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/list-by-page")
    public R<List<MamberElderVo>> listByPage(@RequestHeader("authorization") String authorization, Integer pageNum, Integer pageSize){
        return R.ok(familyMemberService.listElder(authorization, pageNum, pageSize));
    }

    /**
     * 查询健康数据
     * @param authorization
     * @param deviceDto
     * @return
     */
    @PostMapping("/QueryDevicePropertyStatus")
    public R<Map> QueryDevicePropertyStatus(@RequestHeader("authorization") String authorization, @RequestBody DeviceDto deviceDto){
        return R.ok(familyMemberService.queryDevicePropertyStatus(authorization, deviceDto));
    }


    /**
     * 按天统计查询指标数据
     * @param queryDeviceDataDto
     * @return
     */
    @ApiOperation("按天统计查询指标数据")
    @GetMapping("/queryDeviceDataListByDay")
    public R<List<QueryDeviceDataVo>> queryDeviceDataListByDay(QueryDeviceDataDto queryDeviceDataDto){
       List<QueryDeviceDataVo> queryDeviceDataVoList = deviceDataService.queryDeviceDataListByDay(queryDeviceDataDto);
        return R.ok(queryDeviceDataVoList);
    }

    @ApiOperation("按周统计查询指标数据")
    @GetMapping("/queryDeviceDataListByWeek")
    public R<List<QueryDeviceDataVo>> queryDeviceDataListByWeek(QueryDeviceDataDto queryDeviceDataDto){
        List<QueryDeviceDataVo> queryDeviceDataVoList = deviceDataService.queryDeviceDataListByWeek(queryDeviceDataDto);
        return R.ok(queryDeviceDataVoList);
    }

}
